<include file="Public/header" />
<style>
.shop_sort .shop_sort_title{width:10%;}
.pic_container{float:left;width:88%;}
.pic_wrapper{float:left;width:110px;height:110px;position:relative;}
.pic_wrapper img{margin:10px 10px 10px 0;max-width:100px;max-height:100px;z-index:1;}
.pic_wrapper div{display:none;position:absolute;top:10px;width: 100px;height: 100px;color: #fff;background: rgba(0,0,0,0.6);line-height:100px;vertical-align: middle;text-align: center;font-size:18px;cursor:pointer;}
</style>
        <div class="comm-top">
            <h4 style="margin-bottom:0">{:$formData['id']?'修改':'添加'}商品信息</h4>
            <div class="add_page_top"></div>
        </div>
        <form id="dataFrom" onsubmit="return false;">
            <input type="hidden" name="info[type]" value="3" />
            <input type="hidden" name="info[id]" value="{$formData.id}" />
            <div class="shop_sort_box">
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品名称：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[goods_name]" value="{$formData.goods_name}" type="text" placeholder="请输入商品名称"/>
                    </div>
                </div>

                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品配图：</h4></div>
                    <div class="shop_sort_set" style="position:relative;">
                        <input class="shop_sort_text" type="text" onclick="up_img_fun('{:U('Upload/index')}')" />
                        <a href="javascript:void(0);" class="btn-upload" onclick="up_img_fun('{:U('Upload/index')}')">
                            <i class="icons icons-upload"></i>上传
                        </a>
                        <span class="input_span_extra">&nbsp;&nbsp;&nbsp;建议图片尺寸260px*260px</span>
                    </div>
                    <div class="pic_container">
                    <foreach name="formData.goods_pics" item="val">
                        <div class="pic_wrapper">
                            <input type="hidden" name="goods_pics[]" value="{$val}"/>
                            <img src="{$val}"/>
                            <div>删 除</div>
                        </div>
                    </foreach>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>兑换积分：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[integral_price]" value="{$formData.integral_price}" type="number" placeholder="请输入兑换所需积分"/>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>库存：</h4></div>
                    <div class="shop_sort_set">
                        <input class="shop_sort_text" name="info[store]" value="{$formData.store|default=0}" type="text" placeholder="请输入商品库存"/>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品简介：</h4></div>
                    <div class="shop_sort_set">
                        <textarea class="shop_sort_text" name="info[profile]" placeholder="请输入介绍" style="height:80px;">{$formData.profile}</textarea>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4><must>*</must>商品详情：</h4></div>
                    <div class="shop_sort_set">
                        <textarea  id="detail" name="info[detail]" style="height:120px;width:600px;">{$formData.detail}</textarea>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title"><h4>状态：</h4></div>
                    <div class="shop_sort_set rdo">
                        <label class="lbl"><span><input type="radio" name="info[status]" {:$formData['status']!='2'?'checked':''} value='1'></span><span>上架</span></label>
                        <label class="lbl"><span><input type="radio" name="info[status]" {:$formData['status']=='2'?'checked':''} value='2'></span><span>下架</span></label>
                    </div>
                </div>
                <div class="shop_sort">
                    <div class="shop_sort_title">
                        <h4>&nbsp;</h4>
                    </div>
                    <div class="shop_sort_set">
                        <span onclick="save(this);return false" id="saveBtn" class="btngreen30">完成</span>
                        &nbsp;&nbsp;&nbsp;
                        <span onclick="history.go(-1);" class="btngray30">返回</span>
                    </div>
                </div>
            </div>
        </form>
        
<!-- 上传图片开始 --> 
<link rel="stylesheet" type="text/css" href="__PUBLIC__/upimg/css/upimg.css" />
<script type="text/javascript" src="__PUBLIC__/upimg/upimg.js"></script>
<script type="text/javascript">
/**
 * up_img_fun(up_img_php) 执行上传的函数，微沟通图片上传的改版
 * @param string up_img_php 后台处理图片上传的文件
 * 
 * up_img_notify(img_path) 上传回调函数
 * @param string img_path 返回的图片地址，图片仍放在/data/image_c/下
 */
function up_img_notify(img_path){
    var str = '';
    str += '<div class="pic_wrapper">';
    str += '<input type="hidden" name="goods_pics[]" value="'+img_path+'"/>';
    str += '<img src="'+img_path+'"/>';
    str += '<div>删 除</div>';
    str += '</div>';
    $('.pic_container').append(str);
}
</script>
<!-- 上传图片结束 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<script>
$(function(){
    //初始化编辑器
    UE.getEditor('detail', {
        toolbars: [['source','bold','italic','underline','fontsize','forecolor','backcolor','pasteplain',
        'insertorderedlist','cleardoc','link','simpleupload','emotion','map','inserttable',
        //'insertimage',//多图上传
        ]]
    });
    $('.pic_container').on('mouseover','.pic_wrapper img',function(){
        $(this).next().show();
    })
    $('.pic_container').on('mouseout','.pic_wrapper div',function(){
        $(this).hide();
    })
    $('.pic_container').on('click','.pic_wrapper div',function(){
        $(this).parent('.pic_wrapper').remove();
    })
});
function save(obj){
    $.post('{:U("save")}',$('#dataFrom').serialize(),function(res){
        if(res.status == 1){
            note_info(res.info,obj);
            setTimeout('window.location.href="'+document.referrer+'"',1200);
        }else{
            note_info(res.info,obj,'warn');
        }
    })
}
</script>
<include file="Public/footer"/>
